﻿package  
{
	import flash.display.Sprite;
	import flash.net.URLRequest;
	import flash.display.Loader;
	import flash.events.*;
	import flash.filters.GlowFilter;
	import flash.filters.DropShadowFilter;
	import flash.filters.BlurFilter;
 
	public class Irudia extends Sprite
	{
		
		private var argiKolorea:String;
 
		public function Irudia(url:String)
		{
			var loader:Loader = new Loader();
			loader.contentLoaderInfo.addEventListener(Event.COMPLETE, imagenCargada);
			loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, imagenError);
			loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, imagenProgreso);
			loader.load( new URLRequest(url));
			name = url;
			argiKolorea="beltza";
			
		}
		
		public function setIzena(i:String){
			name=i;
		}
		
		public function setArgiKolorea(a:String){
			argiKolorea=a;
		}
		
		public function argitu(){
			var argitu:GlowFilter = new GlowFilter();
				argitu.alpha=1;
				
				switch (argiKolorea)
				{				
				case "beltza" :
					argitu.color=0x000000;
					break;
				case "urdina" :				
					argitu.color=0x0000FF;
					break;
				case "horia" :
					argitu.color=0xFFFF00;		
					break;
				case "gorria" :
					argitu.color=0xFF0000;
					break;
				
			}//switch
			this.filters = [argitu];
		}
		
		public function amatatu(){
			var argitu:GlowFilter = new GlowFilter();
			argitu.alpha=0,5;
			this.filters = [argitu];
		}
		
		public function sombra(){
			   
			var sombra:DropShadowFilter = new DropShadowFilter();
			sombra.strength = 5;
			sombra.alpha = 0.50;
			sombra.color = 0x000000;
			this.filters = [sombra];
		}
		
		public function lainotu(){
     
			var desenfocar:BlurFilter = new BlurFilter ();
			desenfocar.blurX = 5;
			desenfocar.blurY = 5;
			desenfocar.quality= 3;
			this.filters = [desenfocar];
		}
		
		public function ezabatu(funtzioa:Function){
			this.alpha = 0,5;
			this.removeEventListener(MouseEvent.CLICK, funtzioa);
			
		}
 
		private function imagenCargada(e:Event):void {
			//trace("Cargada: " + e);
			addChild(e.target.content); //Beharrezkoa
			
			
		}
 
		private function imagenError(e:IOErrorEvent):void {
			trace("Error: " + e);
		}
 
		private function imagenProgreso(e:ProgressEvent):void {
			//trace("Cargados=" + e.bytesLoaded + " Total=" + e.bytesTotal);
		}
 
	}
 
}
